<?php
/*
Plugin Name: Megatop
Plugin URI: http://vmrf.ru
Description: Show mega top news
Author: vmrf.ru
Version: 1.0
Author URI: http://vmrf.ru
 */

namespace AY\Widget;

class Megatop2 extends \AY\Widget\AWidget
{
    protected $widgetName = 'Megatop2';
    protected $widgetOptions = array(
        'classname' => 'megatop2-ay',
        'description'   => 'widget show megtop news'
        );
    //protected $countPost = 10;
    protected $category = 18; //ay()->region()->getRegionCategory();


    protected function getData() {

        return wp_get_recent_posts(array('numberposts'=>5,'category'=>$this->category, 'post_status'=>'publish'));

    }

    function widget( $args, $instance ) {
        $resentPost = $this->getData();
        ?>
  <div id="slider">
          <div id="nav"></div>
          <div class="slider_content">
<?php
        foreach ($resentPost as $post) {
            ?>
            <div class="item clearfix"><a href="<?php echo get_permalink($post["ID"]);?>" title="<?php echo $post["post_title"];?>"><?php echo get_the_post_thumbnail($post["ID"],array(400,300)); ?></a>

              <div class="desc">
               <h2><a href="<?php echo get_permalink($post["ID"]);?>" title="<?php echo $post["post_title"];?>"> <?php echo $post["post_title"];?></a></h2>
                 <p><?php echo $post["post_excerpt"];?></p>
              </div>
            </div>
<?php
        }
    ?>
          </div>
   </div>
<?php
}

    function form( $instance ) {
    $count = esc_attr($instance['count']);?>
<label for="<?php echo $this->get_field_id('count');?>">Количество новостей</label>
    <input class="widefat" id="<?php echo $this->get_field_id('count');?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo $count;?>">
    <?php }

    function update($new_instance, $old_instance) {
    return $new_instance;
    }

}
